<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::middleware('auth:api')->get('/user', function (Request $request) {
//     return $request->user();
// });

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// })->name('user');

Route::post('/sanctum/token', 'Api\LoginController@login')->name('login');

Route::group(['middleware'=>[]], function () {
    Route::group(['prefix'=>'thirdparty','as'=>'thirdparty.','middleware'=>[]], function () {
        Route::post('getUserToken', 'Api\ThirdpartyController@getUserToken')->name('getUserToken');
        Route::post('getUserTokens', 'Api\ThirdpartyController@getUserTokens')->name('getUserTokens');
        Route::post('deleteUserToken', 'Api\ThirdpartyController@deleteUserToken')->name('deleteUserToken');
    });
});

Route::group(['middleware'=>[]], function () {
    Route::group(['prefix'=>'user','as'=>'user.','middleware'=>[]], function () {
        Route::get('users', 'Api\UserController@users')->name('users');
    });
});

Route::group(['middleware'=>['auth:sanctum']], function () {
    Route::group(['prefix'=>'user','as'=>'user.','middleware'=>[]], function () {
        Route::get('', 'Api\UserController@show')->name('show');
    });
    Route::group(['prefix'=>'im','as'=>'im.','middleware'=>[]], function () {
        Route::post('bindUid', 'Api\ImController@bindUid')->name('bindUid');
        Route::post('send', 'Api\ImController@send')->name('send');
        Route::post('joinGroup', 'Api\ImController@joinGroup')->name('joinGroup');
        Route::get('messages', 'Api\ImController@messages')->name('messages');
        Route::get('getLatestMessages', 'Api\ImController@getLatestMessages')->name('getLatestMessages');
        Route::get('getGroupUsers', 'Api\ImController@getGroupUsers')->name('getGroupUsers');
        Route::get('userToUserGroup', 'Api\ImController@userToUserGroup')->name('userToUserGroup');
    });

    Route::group(['prefix'=>'randomchat','as'=>'randomchat.','middleware'=>[]], function () {
        Route::get('byGroupId', 'Api\RandomChatController@byGroupId')->name('byGroupId');
        Route::post('join', 'Api\RandomChatController@join')->name('join');//主动加入
        Route::post('apply', 'Api\RandomChatController@apply')->name('apply');//申请加入
        Route::post('vote', 'Api\RandomChatController@vote')->name('vote');//申请加入
    });
    Route::group(['prefix'=>'messageaction','as'=>'messageaction.','middleware'=>[]], function () {
        Route::post('vote', 'Api\MessageActionController@vote')->name('vote');//消息投票
    });
    Route::group(['prefix'=>'post','as'=>'post.','middleware'=>[]], function () {
        Route::get('index', 'Api\PostController@index')->name('index');//朋友圈列表
        Route::post('publish', 'Api\PostController@publish')->name('publish');//发布朋友圈
        Route::post('joinGroup', 'Api\PostController@joinGroup')->name('joinGroup');//加入朋友圈群聊
    });
    
    // Route::group(['prefix'=>'upload','as'=>'upload.','middleware'=>[]],function () {
    //     Route::post('image', 'Api\UploadController@image')->name('image');
    //     Route::post('file', 'Api\UploadController@file')->name('file');
    //     Route::post('audio', 'Api\UploadController@audio')->name('audio');//base64
    //     Route::post('fileAudio', 'Api\UploadController@fileAudio')->name('fileAudio');//文件
    // });
});
Route::group(['middleware'=>[]], function () {
    Route::group(['prefix'=>'im','as'=>'im.','middleware'=>[]], function () {
        Route::post('bindGroupUid', 'Api\ImController@bindGroupUid')->name('bindGroupUid');
        Route::post('groupSend', 'Api\ImController@groupSend')->name('groupSend');
    });
    Route::group(['prefix'=>'upload','as'=>'upload.','middleware'=>[]], function () {
        Route::post('image', 'Api\UploadController@image')->name('image');
        Route::post('file', 'Api\UploadController@file')->name('file');
        Route::post('video', 'Api\UploadController@video')->name('video');
        Route::post('audio', 'Api\UploadController@audio')->name('audio');//base64
        Route::post('fileAudio', 'Api\UploadController@fileAudio')->name('fileAudio');//文件
    });
});
